package com.playball.lottery.frm.help;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;

import com.playball.lottery.R;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.nt.GetJsonData;


/**
 * @author tanglizhong
 * @version 2014-6-5 下午3:32:40
 */
public class CaiPiaoHelp extends BaseActivity {

	// 顶部菜单栏
	private Button top_title_back;
	private TextView top_title_info;
	private Button top_title_refres;
	private WebView webView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ad);

		initView();
		initData();
	}

	/**
	 * 初始化组件
	 */
	private void initView() {
		top_title_back = (Button) findViewById(R.id.top_title_back);
		top_title_back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		top_title_info = (TextView) findViewById(R.id.top_title_info);
		top_title_refres = (Button) findViewById(R.id.top_title_refres);
		top_title_refres.setVisibility(View.INVISIBLE);
		webView = (WebView) findViewById(R.id.web);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
		webView.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
		});
	}

	/**
	 * 初始化数据
	 */
	private void initData() {
		Intent intent = getIntent();
		String title = intent.getStringExtra("cp_title");
		String url = intent.getStringExtra("cp_url");
		if (url != null) {
			if(title.equals("六合彩")){
				url = "file:///android_asset/"+url;
			}else if (url.toLowerCase().trim().indexOf(GetJsonData.helpPath) != 0) {
				url = GetJsonData.helpPath + url;
			}
		}
		top_title_info.setText(title);
		webView.loadUrl(url);
	}

	public void onResume() {
		super.onResume();
		
	}

	public void onPause() {
		super.onPause();
		
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
			webView.goBack();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

}
